// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

#nullable restore
namespace Elastic.Clients.Elasticsearch
{
	public sealed partial class RankEvalRequestItem
	{
		[JsonInclude]
		[JsonPropertyName("id")]
		public Elastic.Clients.Elasticsearch.Id Id { get; set; }

		[JsonInclude]
		[JsonPropertyName("params")]
		public Dictionary<string, object>? Params { get; set; }

		[JsonInclude]
		[JsonPropertyName("ratings")]
		public IEnumerable<Elastic.Clients.Elasticsearch.DocumentRating> Ratings { get; set; }

		[JsonInclude]
		[JsonPropertyName("request")]
		public Elastic.Clients.Elasticsearch.RankEvalQuery? Request { get; set; }

		[JsonInclude]
		[JsonPropertyName("template_id")]
		public Elastic.Clients.Elasticsearch.Id? TemplateId { get; set; }
	}

	public sealed partial class RankEvalRequestItemDescriptor<TDocument> : SerializableDescriptorBase<RankEvalRequestItemDescriptor<TDocument>>
	{
		internal RankEvalRequestItemDescriptor(Action<RankEvalRequestItemDescriptor<TDocument>> configure) => configure.Invoke(this);
		public RankEvalRequestItemDescriptor() : base()
		{
		}

		private Elastic.Clients.Elasticsearch.RankEvalQuery? RequestValue { get; set; }

		private RankEvalQueryDescriptor<TDocument> RequestDescriptor { get; set; }

		private Action<RankEvalQueryDescriptor<TDocument>> RequestDescriptorAction { get; set; }

		private Elastic.Clients.Elasticsearch.Id IdValue { get; set; }

		private Dictionary<string, object>? ParamsValue { get; set; }

		private IEnumerable<Elastic.Clients.Elasticsearch.DocumentRating> RatingsValue { get; set; }

		private DocumentRatingDescriptor RatingsDescriptor { get; set; }

		private Action<DocumentRatingDescriptor> RatingsDescriptorAction { get; set; }

		private Action<DocumentRatingDescriptor>[] RatingsDescriptorActions { get; set; }

		private Elastic.Clients.Elasticsearch.Id? TemplateIdValue { get; set; }

		public RankEvalRequestItemDescriptor<TDocument> Request(Elastic.Clients.Elasticsearch.RankEvalQuery? request)
		{
			RequestDescriptor = null;
			RequestDescriptorAction = null;
			RequestValue = request;
			return Self;
		}

		public RankEvalRequestItemDescriptor<TDocument> Request(RankEvalQueryDescriptor<TDocument> descriptor)
		{
			RequestValue = null;
			RequestDescriptorAction = null;
			RequestDescriptor = descriptor;
			return Self;
		}

		public RankEvalRequestItemDescriptor<TDocument> Request(Action<RankEvalQueryDescriptor<TDocument>> configure)
		{
			RequestValue = null;
			RequestDescriptor = null;
			RequestDescriptorAction = configure;
			return Self;
		}

		public RankEvalRequestItemDescriptor<TDocument> Id(Elastic.Clients.Elasticsearch.Id id)
		{
			IdValue = id;
			return Self;
		}

		public RankEvalRequestItemDescriptor<TDocument> Params(Func<FluentDictionary<string, object>, FluentDictionary<string, object>> selector)
		{
			ParamsValue = selector?.Invoke(new FluentDictionary<string, object>());
			return Self;
		}

		public RankEvalRequestItemDescriptor<TDocument> Ratings(IEnumerable<Elastic.Clients.Elasticsearch.DocumentRating> ratings)
		{
			RatingsDescriptor = null;
			RatingsDescriptorAction = null;
			RatingsDescriptorActions = null;
			RatingsValue = ratings;
			return Self;
		}

		public RankEvalRequestItemDescriptor<TDocument> Ratings(DocumentRatingDescriptor descriptor)
		{
			RatingsValue = null;
			RatingsDescriptorAction = null;
			RatingsDescriptorActions = null;
			RatingsDescriptor = descriptor;
			return Self;
		}

		public RankEvalRequestItemDescriptor<TDocument> Ratings(Action<DocumentRatingDescriptor> configure)
		{
			RatingsValue = null;
			RatingsDescriptor = null;
			RatingsDescriptorActions = null;
			RatingsDescriptorAction = configure;
			return Self;
		}

		public RankEvalRequestItemDescriptor<TDocument> Ratings(params Action<DocumentRatingDescriptor>[] configure)
		{
			RatingsValue = null;
			RatingsDescriptor = null;
			RatingsDescriptorAction = null;
			RatingsDescriptorActions = configure;
			return Self;
		}

		public RankEvalRequestItemDescriptor<TDocument> TemplateId(Elastic.Clients.Elasticsearch.Id? templateId)
		{
			TemplateIdValue = templateId;
			return Self;
		}

		protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
		{
			writer.WriteStartObject();
			if (RequestDescriptor is not null)
			{
				writer.WritePropertyName("request");
				JsonSerializer.Serialize(writer, RequestDescriptor, options);
			}
			else if (RequestDescriptorAction is not null)
			{
				writer.WritePropertyName("request");
				JsonSerializer.Serialize(writer, new RankEvalQueryDescriptor<TDocument>(RequestDescriptorAction), options);
			}
			else if (RequestValue is not null)
			{
				writer.WritePropertyName("request");
				JsonSerializer.Serialize(writer, RequestValue, options);
			}

			writer.WritePropertyName("id");
			JsonSerializer.Serialize(writer, IdValue, options);
			if (ParamsValue is not null)
			{
				writer.WritePropertyName("params");
				JsonSerializer.Serialize(writer, ParamsValue, options);
			}

			if (RatingsDescriptor is not null)
			{
				writer.WritePropertyName("ratings");
				writer.WriteStartArray();
				JsonSerializer.Serialize(writer, RatingsDescriptor, options);
				writer.WriteEndArray();
			}
			else if (RatingsDescriptorAction is not null)
			{
				writer.WritePropertyName("ratings");
				writer.WriteStartArray();
				JsonSerializer.Serialize(writer, new DocumentRatingDescriptor(RatingsDescriptorAction), options);
				writer.WriteEndArray();
			}
			else if (RatingsDescriptorActions is not null)
			{
				writer.WritePropertyName("ratings");
				writer.WriteStartArray();
				foreach (var action in RatingsDescriptorActions)
				{
					JsonSerializer.Serialize(writer, new DocumentRatingDescriptor(action), options);
				}

				writer.WriteEndArray();
			}
			else
			{
				writer.WritePropertyName("ratings");
				JsonSerializer.Serialize(writer, RatingsValue, options);
			}

			if (TemplateIdValue is not null)
			{
				writer.WritePropertyName("template_id");
				JsonSerializer.Serialize(writer, TemplateIdValue, options);
			}

			writer.WriteEndObject();
		}
	}

	public sealed partial class RankEvalRequestItemDescriptor : SerializableDescriptorBase<RankEvalRequestItemDescriptor>
	{
		internal RankEvalRequestItemDescriptor(Action<RankEvalRequestItemDescriptor> configure) => configure.Invoke(this);
		public RankEvalRequestItemDescriptor() : base()
		{
		}

		private Elastic.Clients.Elasticsearch.RankEvalQuery? RequestValue { get; set; }

		private RankEvalQueryDescriptor RequestDescriptor { get; set; }

		private Action<RankEvalQueryDescriptor> RequestDescriptorAction { get; set; }

		private Elastic.Clients.Elasticsearch.Id IdValue { get; set; }

		private Dictionary<string, object>? ParamsValue { get; set; }

		private IEnumerable<Elastic.Clients.Elasticsearch.DocumentRating> RatingsValue { get; set; }

		private DocumentRatingDescriptor RatingsDescriptor { get; set; }

		private Action<DocumentRatingDescriptor> RatingsDescriptorAction { get; set; }

		private Action<DocumentRatingDescriptor>[] RatingsDescriptorActions { get; set; }

		private Elastic.Clients.Elasticsearch.Id? TemplateIdValue { get; set; }

		public RankEvalRequestItemDescriptor Request(Elastic.Clients.Elasticsearch.RankEvalQuery? request)
		{
			RequestDescriptor = null;
			RequestDescriptorAction = null;
			RequestValue = request;
			return Self;
		}

		public RankEvalRequestItemDescriptor Request(RankEvalQueryDescriptor descriptor)
		{
			RequestValue = null;
			RequestDescriptorAction = null;
			RequestDescriptor = descriptor;
			return Self;
		}

		public RankEvalRequestItemDescriptor Request(Action<RankEvalQueryDescriptor> configure)
		{
			RequestValue = null;
			RequestDescriptor = null;
			RequestDescriptorAction = configure;
			return Self;
		}

		public RankEvalRequestItemDescriptor Id(Elastic.Clients.Elasticsearch.Id id)
		{
			IdValue = id;
			return Self;
		}

		public RankEvalRequestItemDescriptor Params(Func<FluentDictionary<string, object>, FluentDictionary<string, object>> selector)
		{
			ParamsValue = selector?.Invoke(new FluentDictionary<string, object>());
			return Self;
		}

		public RankEvalRequestItemDescriptor Ratings(IEnumerable<Elastic.Clients.Elasticsearch.DocumentRating> ratings)
		{
			RatingsDescriptor = null;
			RatingsDescriptorAction = null;
			RatingsDescriptorActions = null;
			RatingsValue = ratings;
			return Self;
		}

		public RankEvalRequestItemDescriptor Ratings(DocumentRatingDescriptor descriptor)
		{
			RatingsValue = null;
			RatingsDescriptorAction = null;
			RatingsDescriptorActions = null;
			RatingsDescriptor = descriptor;
			return Self;
		}

		public RankEvalRequestItemDescriptor Ratings(Action<DocumentRatingDescriptor> configure)
		{
			RatingsValue = null;
			RatingsDescriptor = null;
			RatingsDescriptorActions = null;
			RatingsDescriptorAction = configure;
			return Self;
		}

		public RankEvalRequestItemDescriptor Ratings(params Action<DocumentRatingDescriptor>[] configure)
		{
			RatingsValue = null;
			RatingsDescriptor = null;
			RatingsDescriptorAction = null;
			RatingsDescriptorActions = configure;
			return Self;
		}

		public RankEvalRequestItemDescriptor TemplateId(Elastic.Clients.Elasticsearch.Id? templateId)
		{
			TemplateIdValue = templateId;
			return Self;
		}

		protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
		{
			writer.WriteStartObject();
			if (RequestDescriptor is not null)
			{
				writer.WritePropertyName("request");
				JsonSerializer.Serialize(writer, RequestDescriptor, options);
			}
			else if (RequestDescriptorAction is not null)
			{
				writer.WritePropertyName("request");
				JsonSerializer.Serialize(writer, new RankEvalQueryDescriptor(RequestDescriptorAction), options);
			}
			else if (RequestValue is not null)
			{
				writer.WritePropertyName("request");
				JsonSerializer.Serialize(writer, RequestValue, options);
			}

			writer.WritePropertyName("id");
			JsonSerializer.Serialize(writer, IdValue, options);
			if (ParamsValue is not null)
			{
				writer.WritePropertyName("params");
				JsonSerializer.Serialize(writer, ParamsValue, options);
			}

			if (RatingsDescriptor is not null)
			{
				writer.WritePropertyName("ratings");
				writer.WriteStartArray();
				JsonSerializer.Serialize(writer, RatingsDescriptor, options);
				writer.WriteEndArray();
			}
			else if (RatingsDescriptorAction is not null)
			{
				writer.WritePropertyName("ratings");
				writer.WriteStartArray();
				JsonSerializer.Serialize(writer, new DocumentRatingDescriptor(RatingsDescriptorAction), options);
				writer.WriteEndArray();
			}
			else if (RatingsDescriptorActions is not null)
			{
				writer.WritePropertyName("ratings");
				writer.WriteStartArray();
				foreach (var action in RatingsDescriptorActions)
				{
					JsonSerializer.Serialize(writer, new DocumentRatingDescriptor(action), options);
				}

				writer.WriteEndArray();
			}
			else
			{
				writer.WritePropertyName("ratings");
				JsonSerializer.Serialize(writer, RatingsValue, options);
			}

			if (TemplateIdValue is not null)
			{
				writer.WritePropertyName("template_id");
				JsonSerializer.Serialize(writer, TemplateIdValue, options);
			}

			writer.WriteEndObject();
		}
	}
}